
<!DOCTYPE html>
<html lang="">


<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
  <meta name="theme-color" content="#202020">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <script src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" async></script>
  
  
    <meta name="keywords" content="Github,">
  

  
    <meta name="description" content="Github小白指南">
  
  
  <link rel="icon" type="image/x-icon" href="/logo.png">
  <title>Github小白指南 [ 复制粘贴工程师 ]</title>
  
    <!-- stylesheets list from config.yml -->
    
      <link rel="stylesheet" href="//cdn.bootcss.com/pure/1.0.0/pure-min.css">
    
      <link rel="stylesheet" href="/css/xoxo.css">
    
  
</head>


<body>
  <div class="nav-container">
    <nav class="home-menu pure-menu pure-menu-horizontal">
  <a class="pure-menu-heading" href="/">
    <img class="avatar" src="https://wx.qlogo.cn/mmopen/vi_32/AMpRacDgkTPogKk4gQ5IC3QezP55XoPpicQpnD9Vz3eNz6OPFYyFrFzCa4EGQGH65kPia5YJwQBBvvJpVwQ4lfVg/132">
    <span class="title">复制粘贴工程师</span>
  </a>

  <ul class="pure-menu-list clearfix">
      
          
            <li class="pure-menu-item"><a href="/" class="pure-menu-link">首页</a></li>
          
      
          
            <li class="pure-menu-item"><a href="/search" class="pure-menu-link">搜索</a></li>
          
      
  </ul>

</nav>
  </div>

  <div class="container" id="content-outer">
    <div class="inner" id="content-inner">
      <div class="post-container">
  <article class="post" id="post">
    <header class="post-header text-center">
      <h1 class="title">
        Github小白指南
      </h1>
      <span>
        
        <time class="time" datetime="2019-02-28T03:23:39.000Z">
        2019-02-28
      </time>
        
      </span>
      <span class="slash">/</span>
      <span class="post-meta">
      <span class="post-tags">
        <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Github/">Github</a></li></ul>
      </span>
    </span>
      <span class="slash">/</span>
      <span class="read">
      <span id="busuanzi_value_page_pv"></span> 点击
    </span>
      <span class="slash">/</span>
    </header>

    <div class="post-content">
      <p>咳咳，有如此完美的可视化界面不用，偏偏要用命令行，何必呢！命令行这东西，按需获取，当你遇到需要完成的操作无从下手时，可以过来看看，没必要全部记下来。<br><a id="more"></a></p>
<p>老司机专属链接：<a href="#list">Git 常用命令列表</a></p>
<h4 id="零基础：仓库初长成"><a href="#零基础：仓库初长成" class="headerlink" title="零基础：仓库初长成"></a>零基础：仓库初长成</h4><h5 id="Scene1-我是项目的创建者，在git上已经创建了一个新的仓库，我要怎么推送本地代码到远端仓库？"><a href="#Scene1-我是项目的创建者，在git上已经创建了一个新的仓库，我要怎么推送本地代码到远端仓库？" class="headerlink" title="Scene1: 我是项目的创建者，在git上已经创建了一个新的仓库，我要怎么推送本地代码到远端仓库？"></a>Scene1: 我是项目的创建者，在git上已经创建了一个新的仓库，我要怎么推送本地代码到远端仓库？</h5><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> git init <span class="comment">// 在项目的根目录执行，初始化本地仓库</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.</span> git remote add [rmt_name] [git_url]  <span class="comment">// 构建远程仓库连接</span></span><br><span class="line"></span><br><span class="line"><span class="number">3.</span> git push [rmt_name] master   <span class="comment">// 将本地代码推送到远端的master分支</span></span><br></pre></td></tr></table></figure>
<h5 id="Scene2-我是项目的参与者，git上已经有了代码仓库，我要怎么参与开发？"><a href="#Scene2-我是项目的参与者，git上已经有了代码仓库，我要怎么参与开发？" class="headerlink" title="Scene2: 我是项目的参与者，git上已经有了代码仓库，我要怎么参与开发？"></a>Scene2: 我是项目的参与者，git上已经有了代码仓库，我要怎么参与开发？</h5><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git clone [git_url]   <span class="comment">// 复制远程仓库到本地</span></span><br></pre></td></tr></table></figure>
<hr>
<h4 id="入门：贡献自己一份力"><a href="#入门：贡献自己一份力" class="headerlink" title="入门：贡献自己一份力"></a>入门：贡献自己一份力</h4><h5 id="Scene1-我对本地仓库进行了修改，我要怎么提交到远端仓库？"><a href="#Scene1-我对本地仓库进行了修改，我要怎么提交到远端仓库？" class="headerlink" title="Scene1: 我对本地仓库进行了修改，我要怎么提交到远端仓库？"></a>Scene1: 我对本地仓库进行了修改，我要怎么提交到远端仓库？</h5><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> git status   <span class="comment">// 查看哪些文件被修改了，发现所有的文件修改都是你所希望的</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.</span> git add .    <span class="comment">// 将所有的文件修改都添加到暂存区</span></span><br><span class="line"></span><br><span class="line"><span class="number">3.</span> git commit -m <span class="string">"本次提交的信息"</span>   <span class="comment">// 将暂存区的内容提交到本地仓库</span></span><br><span class="line"></span><br><span class="line"><span class="number">4.</span> git pull [origin] [branch_name]     <span class="comment">// 拉取并合并远端的仓库，发现没有任何冲突，太开心了</span></span><br><span class="line"></span><br><span class="line"><span class="number">5.</span> git push [origin] [branch_name] <span class="comment">// 将本地仓库提交到远端仓库</span></span><br></pre></td></tr></table></figure>
<h5 id="Scene2-我想撤销对某些文件的修改-还没有add"><a href="#Scene2-我想撤销对某些文件的修改-还没有add" class="headerlink" title="Scene2: 我想撤销对某些文件的修改(还没有add)"></a>Scene2: 我想撤销对某些文件的修改(还没有add)</h5><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> git status <span class="comment">// 查看哪些文件被修改了，发现有些文件不应该被修改</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.</span> git checkout [file_name] <span class="comment">// 撤销对原有文件的修改，如果有多个文件，重复执行此操作</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 2. 如果想撤销所有修改，git checkout .</span></span><br><span class="line"></span><br><span class="line"><span class="number">3.</span> git clean -df <span class="comment">// 恢复新增的或删除的文件</span></span><br></pre></td></tr></table></figure>
<h5 id="Scene3-我想撤回add操作（已经add但是还没commit）"><a href="#Scene3-我想撤回add操作（已经add但是还没commit）" class="headerlink" title="Scene3: 我想撤回add操作（已经add但是还没commit）"></a>Scene3: 我想撤回add操作（已经add但是还没commit）</h5><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git reset    <span class="comment">// 把add的文件全部从暂存区取出来，如果只想取出单个文件，后面可以跟文件名</span></span><br></pre></td></tr></table></figure>
<h5 id="Scene4-我想撤回commit操作（已经commit但是还没有进行push）"><a href="#Scene4-我想撤回commit操作（已经commit但是还没有进行push）" class="headerlink" title="Scene4: 我想撤回commit操作（已经commit但是还没有进行push）"></a>Scene4: 我想撤回commit操作（已经commit但是还没有进行push）</h5><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> git log      <span class="comment">// 查看所有的提交日志，复制上一次commit的commit_id</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.</span> git reset --soft [commit_id] <span class="comment">// 撤销此次commit并保留所有的修改</span></span><br></pre></td></tr></table></figure>
<h5 id="Scene5-我进行了commit操作，但是我发现我的标签写错了，怎么办？"><a href="#Scene5-我进行了commit操作，但是我发现我的标签写错了，怎么办？" class="headerlink" title="Scene5: 我进行了commit操作，但是我发现我的标签写错了，怎么办？"></a>Scene5: 我进行了commit操作，但是我发现我的标签写错了，怎么办？</h5><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> git commit --amend  <span class="comment">// 执行后编辑信息保存即可(你可能需要一些简单的vim知识)</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.</span> git commit --amend --reset-author    <span class="comment">// 修改上一次提交的作者信息</span></span><br></pre></td></tr></table></figure>
<h5 id="Scene6-我想回滚到之前的某一个版本"><a href="#Scene6-我想回滚到之前的某一个版本" class="headerlink" title="Scene6: 我想回滚到之前的某一个版本"></a>Scene6: 我想回滚到之前的某一个版本</h5><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> git log <span class="comment">// 查看提交日志，复制你想要回滚到的那一次提交的commit_id</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 注意：此次回滚为强制回滚，这之后的所有修改都不会被保存</span></span><br><span class="line"><span class="comment">// 如果你后悔了，只需要到远端仓库中复制当前head的commit_id再执行一遍此操作即可</span></span><br><span class="line"><span class="number">2.</span> git reset --hard [commit_id]</span><br><span class="line"></span><br><span class="line"><span class="comment">// 此操作红色报警，不到万不得已千万不要用！！！</span></span><br><span class="line"><span class="number">3.</span> git push -f [rmt_name] [branch_name]   <span class="comment">// 强制覆盖远端仓库，即进行远端仓库的回滚，此操作不可逆</span></span><br></pre></td></tr></table></figure>
<h5 id="Scene7-最不想看到的结果，pull或者merge的时候发生冲突了"><a href="#Scene7-最不想看到的结果，pull或者merge的时候发生冲突了" class="headerlink" title="Scene7: 最不想看到的结果，pull或者merge的时候发生冲突了"></a>Scene7: 最不想看到的结果，pull或者merge的时候发生冲突了</h5><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> 根据合并结果对所有的冲突进行手动处理</span><br><span class="line"></span><br><span class="line"><span class="number">2.</span> git add .</span><br><span class="line"></span><br><span class="line"><span class="number">3.</span> git commit -m <span class="string">"合并信息"</span>     <span class="comment">// 重新提交一遍</span></span><br><span class="line"></span><br><span class="line"><span class="number">4.</span> git push [rmt_name] [branch_name]</span><br></pre></td></tr></table></figure>
<h5 id="Scene8-想查看某个文件具体的修改内容？"><a href="#Scene8-想查看某个文件具体的修改内容？" class="headerlink" title="Scene8: 想查看某个文件具体的修改内容？"></a>Scene8: 想查看某个文件具体的修改内容？</h5><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git diff [file_name] <span class="comment">// 对比该文件修改前后的区别，如果无文件名将对比所有文件的修改</span></span><br></pre></td></tr></table></figure>
<h5 id="Scene9：我想查看所有的提交记录"><a href="#Scene9：我想查看所有的提交记录" class="headerlink" title="Scene9：我想查看所有的提交记录"></a>Scene9：我想查看所有的提交记录</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">1. git log      // 查看所有的提交记录</span><br><span class="line"></span><br><span class="line">2. git log [branch_name]  // 查看某分支的提交记录</span><br><span class="line"></span><br><span class="line">3. glog     // 等价于 git log --oneline，简化日志，一次提交占一行，有利于全局观察</span><br></pre></td></tr></table></figure>
<hr>
<h4 id="进阶：花里胡哨的一份力"><a href="#进阶：花里胡哨的一份力" class="headerlink" title="进阶：花里胡哨的一份力"></a>进阶：花里胡哨的一份力</h4><h5 id="Scene1-我要新建一个分支"><a href="#Scene1-我要新建一个分支" class="headerlink" title="Scene1: 我要新建一个分支"></a>Scene1: 我要新建一个分支</h5><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> git branch [new_branch_name]       <span class="comment">// 创建一个新的分支</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.</span> git checkout [new_branch_name]     <span class="comment">// 如果需要切换到新分支请执行此命令</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 上面两个步骤可以合并为 git checkout -b [branch_name]</span></span><br></pre></td></tr></table></figure>
<h5 id="Scene2-我要查看现有的所有分支"><a href="#Scene2-我要查看现有的所有分支" class="headerlink" title="Scene2: 我要查看现有的所有分支"></a>Scene2: 我要查看现有的所有分支</h5><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git branch  <span class="comment">// 查看分支</span></span><br></pre></td></tr></table></figure>
<h5 id="Scene3-分支开发完了，我要合并到主分支master上"><a href="#Scene3-分支开发完了，我要合并到主分支master上" class="headerlink" title="Scene3: 分支开发完了，我要合并到主分支master上"></a>Scene3: 分支开发完了，我要合并到主分支master上</h5><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> git checkout master  <span class="comment">// 切换到master</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.</span> git merge [branch_name]    <span class="comment">// 合并分支到master，如果有冲突，你懂的</span></span><br><span class="line"></span><br><span class="line"><span class="number">3.</span> git merge --patch [branch_name] [file_name]  <span class="comment">// 只合并单个文件到master上，比较少用</span></span><br></pre></td></tr></table></figure>
<h5 id="Scene4-分支开发完了，也就没有存在的必要了"><a href="#Scene4-分支开发完了，也就没有存在的必要了" class="headerlink" title="Scene4: 分支开发完了，也就没有存在的必要了"></a>Scene4: 分支开发完了，也就没有存在的必要了</h5><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> git branch -d [branch_name]    <span class="comment">// 删除本地分支, -d会判断是否合并，-D会强制删除</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.</span> git push rmt --<span class="keyword">delete</span> [branch_name]    <span class="comment">// 删除远程仓库的分支</span></span><br></pre></td></tr></table></figure>
<hr>
<h4 id="大师：优化提交记录-rebase"><a href="#大师：优化提交记录-rebase" class="headerlink" title="大师：优化提交记录  - rebase"></a>大师：优化提交记录  - rebase</h4><ul>
<li>超高能警报！！虽然rebase可以简化提交记录，如果你用的是 <code>Source Tree</code> 等可视化工具，那么点一下就可以了，如果是用的命令行，请在熟练使用过 <code>rebase</code> 命令的高手陪伴下使用该命令！！！否则！！！后果你承担不起！！！</li>
</ul>
<blockquote>
<p>普通的提交最大的问题，就是有太多的 <code>commit</code>，当参与人数较多时，会出现大量的如merge这种无用的commit日志，而且在查看提交记录图时，会有很多从分支上合并到主分支的线条，看起来不美观。</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 下面的流程会把本地的commit一一粘贴到master上，而不是merge</span></span><br><span class="line"><span class="comment">// 2、3步骤可以合并为 git pull -rebase orgin master</span></span><br><span class="line"><span class="number">1.</span> git commit -m <span class="string">''</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.</span> git fetch orgin/master</span><br><span class="line"></span><br><span class="line"><span class="number">3.</span> git rebase orgin/master</span><br><span class="line"></span><br><span class="line"><span class="number">4.</span> git push orgin master</span><br></pre></td></tr></table></figure>
<hr>
<h4 id="无卵用：不常用但是一定会用到的命令"><a href="#无卵用：不常用但是一定会用到的命令" class="headerlink" title="无卵用：不常用但是一定会用到的命令"></a>无卵用：不常用但是一定会用到的命令</h4><h5 id="Scene1-管理现有的仓库链接"><a href="#Scene1-管理现有的仓库链接" class="headerlink" title="Scene1: 管理现有的仓库链接"></a>Scene1: 管理现有的仓库链接</h5><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> git remote   <span class="comment">// 查看现有的远程仓库链接名</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.</span> git remote -v    <span class="comment">// 相比于上一条多了url信息，更加详细</span></span><br><span class="line"></span><br><span class="line"><span class="number">3.</span> git remote rm [rmt_name]   <span class="comment">// 删除一个现有链接</span></span><br></pre></td></tr></table></figure>
<h5 id="Scene2-配置本地git的信息"><a href="#Scene2-配置本地git的信息" class="headerlink" title="Scene2: 配置本地git的信息"></a>Scene2: 配置本地git的信息</h5><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> git config --global user.name [user_name]   <span class="comment">// 配置用户名</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.</span> git config --global user.email   [user_email]   <span class="comment">// 配置邮箱</span></span><br></pre></td></tr></table></figure>
<h4 id="打标签（tag）"><a href="#打标签（tag）" class="headerlink" title="打标签（tag）"></a>打标签（tag）</h4><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> git tag v1<span class="number">.0</span> commit_id   <span class="comment">// 给某一此commit添加tag</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.</span> git push origin master --tags <span class="comment">// 把本地的标签push到远程仓库</span></span><br></pre></td></tr></table></figure>
<p><span id="list"></span></p>
<h4 id="Git-常用命令列表"><a href="#Git-常用命令列表" class="headerlink" title="Git 常用命令列表"></a>Git 常用命令列表</h4><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> git init <span class="comment">// 初始化本地仓库</span></span><br><span class="line"><span class="number">2.</span> git remote add [rmt_name] [git_url]  <span class="comment">// 构建远程仓库连接</span></span><br><span class="line"><span class="number">3.</span> git pull [rmt_name] [branch_name]  <span class="comment">// 拉取远程分支并自动合并</span></span><br><span class="line"><span class="number">4.</span> git push [rmt_name] [branch_name]   <span class="comment">// 将本地代码推送到远端的master分支</span></span><br><span class="line"><span class="number">5.</span> git fetch [rmt_name] [branch_name] <span class="comment">// 拉取远程分支，但不自动</span></span><br><span class="line"><span class="number">6.</span> git clone [git_url]   <span class="comment">// 拷贝远程仓库到本地</span></span><br><span class="line"><span class="number">7.</span> git status   <span class="comment">// 查看哪些文件被修改了，发现所有的文件修改都是你所希望的</span></span><br><span class="line"><span class="number">8.</span> git add .    <span class="comment">// 将所有的文件修改都添加到暂存区</span></span><br><span class="line"><span class="number">9.</span> git commit -m <span class="string">"本次提交的信息"</span>   <span class="comment">// 将暂存区的内容提交到本地仓库</span></span><br><span class="line"><span class="number">10.</span> git checkout [file_name] <span class="comment">// 撤销对原有文件的修改，如果有多个文件，重复执行此操作</span></span><br><span class="line"><span class="number">11.</span> git checkout . <span class="comment">// 撤销本次所有的修改</span></span><br><span class="line"><span class="number">12.</span> git clean -df <span class="comment">// 恢复新增的或删除的文件</span></span><br><span class="line"><span class="number">13.</span> git reset    <span class="comment">// 把add的文件全部从暂存区取出来，如果只想取出单个文件，后面可以跟文件名</span></span><br><span class="line"><span class="number">14.</span> git reset --soft [commit_id] <span class="comment">// 撤销此次commit并保留所有的修改</span></span><br><span class="line"><span class="number">15.</span> git reset --hard [commit_id] <span class="comment">// 撤销此次commit并删除所有的修改</span></span><br><span class="line"><span class="number">16.</span> git log      <span class="comment">// 查看所有的提交日志</span></span><br><span class="line"><span class="number">17.</span> git log --oneline <span class="comment">// 查看所有的提交日志（简化版）</span></span><br><span class="line"><span class="number">18.</span> git log [branch_name]  <span class="comment">// 查看某分支的提交记录</span></span><br><span class="line"><span class="number">19.</span> git commit --amend  <span class="comment">// 修改上一次提交的信息（未push）</span></span><br><span class="line"><span class="number">20.</span> git commit --amend --reset-author    <span class="comment">// 修改上一次提交的作者信息（未push）</span></span><br><span class="line"><span class="number">21.</span> git push -f [rmt_name] [branch_name]   <span class="comment">// 强制覆盖远端仓库，即进行远端仓库的回滚，此操作不可逆</span></span><br><span class="line"><span class="number">22.</span> git diff [file_name] <span class="comment">// 对比该文件修改前后的区别，如果无文件名将对比所有文件的修改</span></span><br><span class="line"><span class="number">23.</span> git branch [new_branch_name]       <span class="comment">// 创建一个新的分支</span></span><br><span class="line"><span class="number">24.</span> git checkout [new_branch_name]     <span class="comment">// 切换到新分支</span></span><br><span class="line"><span class="number">25.</span> git branch  <span class="comment">// 查看分支</span></span><br><span class="line"><span class="number">26.</span> git merge [branch_name]    <span class="comment">// 合并分支</span></span><br><span class="line"><span class="number">27.</span> git merge --patch [branch_name] [file_name]  <span class="comment">// 只合并单个文件</span></span><br><span class="line"><span class="number">28.</span> git branch -d [branch_name]    <span class="comment">// 删除本地分支, -d会判断是否合并，-D会强制删除</span></span><br><span class="line"><span class="number">29.</span> git push rmt --<span class="keyword">delete</span> [branch_name]    <span class="comment">// 删除远程仓库的分支</span></span><br><span class="line"><span class="number">30.</span> git remote   <span class="comment">// 查看现有的远程仓库链接名</span></span><br><span class="line"><span class="number">31.</span> git remote -v    <span class="comment">// 相比于上一条多了url信息，更加详细</span></span><br><span class="line"><span class="number">32.</span> git remote rm [rmt_name]   <span class="comment">// 删除一个现有链接</span></span><br><span class="line"><span class="number">33.</span> git config --global user.name [user_name]   <span class="comment">// 配置用户名</span></span><br><span class="line"><span class="number">34.</span> git config --global user.email   [user_email]   <span class="comment">// 配置邮箱</span></span><br><span class="line"><span class="number">35.</span> git tag v1<span class="number">.0</span> commit_id   <span class="comment">// 给某一此commit添加tag</span></span><br><span class="line"><span class="number">36.</span> git push origin master --tags <span class="comment">// 把本地的标签push到远程仓库</span></span><br></pre></td></tr></table></figure>
    </div>

    <div>全文完。</div>
  </article>
  <div class="toc-container">
    
  <div id="toc" class="toc-article">
    <strong class="toc-title">目录</strong>
    <ol class="toc"><li class="toc-item toc-level-4"><a class="toc-link" href="#零基础：仓库初长成"><span class="toc-text">零基础：仓库初长成</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#Scene1-我是项目的创建者，在git上已经创建了一个新的仓库，我要怎么推送本地代码到远端仓库？"><span class="toc-text">Scene1: 我是项目的创建者，在git上已经创建了一个新的仓库，我要怎么推送本地代码到远端仓库？</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#Scene2-我是项目的参与者，git上已经有了代码仓库，我要怎么参与开发？"><span class="toc-text">Scene2: 我是项目的参与者，git上已经有了代码仓库，我要怎么参与开发？</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#入门：贡献自己一份力"><span class="toc-text">入门：贡献自己一份力</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#Scene1-我对本地仓库进行了修改，我要怎么提交到远端仓库？"><span class="toc-text">Scene1: 我对本地仓库进行了修改，我要怎么提交到远端仓库？</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#Scene2-我想撤销对某些文件的修改-还没有add"><span class="toc-text">Scene2: 我想撤销对某些文件的修改(还没有add)</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#Scene3-我想撤回add操作（已经add但是还没commit）"><span class="toc-text">Scene3: 我想撤回add操作（已经add但是还没commit）</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#Scene4-我想撤回commit操作（已经commit但是还没有进行push）"><span class="toc-text">Scene4: 我想撤回commit操作（已经commit但是还没有进行push）</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#Scene5-我进行了commit操作，但是我发现我的标签写错了，怎么办？"><span class="toc-text">Scene5: 我进行了commit操作，但是我发现我的标签写错了，怎么办？</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#Scene6-我想回滚到之前的某一个版本"><span class="toc-text">Scene6: 我想回滚到之前的某一个版本</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#Scene7-最不想看到的结果，pull或者merge的时候发生冲突了"><span class="toc-text">Scene7: 最不想看到的结果，pull或者merge的时候发生冲突了</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#Scene8-想查看某个文件具体的修改内容？"><span class="toc-text">Scene8: 想查看某个文件具体的修改内容？</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#Scene9：我想查看所有的提交记录"><span class="toc-text">Scene9：我想查看所有的提交记录</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#进阶：花里胡哨的一份力"><span class="toc-text">进阶：花里胡哨的一份力</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#Scene1-我要新建一个分支"><span class="toc-text">Scene1: 我要新建一个分支</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#Scene2-我要查看现有的所有分支"><span class="toc-text">Scene2: 我要查看现有的所有分支</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#Scene3-分支开发完了，我要合并到主分支master上"><span class="toc-text">Scene3: 分支开发完了，我要合并到主分支master上</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#Scene4-分支开发完了，也就没有存在的必要了"><span class="toc-text">Scene4: 分支开发完了，也就没有存在的必要了</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#大师：优化提交记录-rebase"><span class="toc-text">大师：优化提交记录  - rebase</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#无卵用：不常用但是一定会用到的命令"><span class="toc-text">无卵用：不常用但是一定会用到的命令</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#Scene1-管理现有的仓库链接"><span class="toc-text">Scene1: 管理现有的仓库链接</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#Scene2-配置本地git的信息"><span class="toc-text">Scene2: 配置本地git的信息</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#打标签（tag）"><span class="toc-text">打标签（tag）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Git-常用命令列表"><span class="toc-text">Git 常用命令列表</span></a></li></ol>
  </div>


  </div>
</div>
<div class="copyright">
    <span>本作品采用</span>
    <a href="https://creativecommons.org/licenses/by/4.0/">知识共享署名 4.0 国际许可协议</a>
    <span>进行许可。 转载时请注明原文链接。</span>
</div>
<div class="share" style="width: 100%;">
  <!-- <img src="https://kevinofneu-blog-static.oss-cn-beijing.aliyuncs.com/static/2018-12-10-qrcode_for_gh_ffacf5722095_258.jpg" alt="Running Geek" style="margin: auto; display: block;"/>

  <div style="margin: auto; text-align: center; font-size: 0.8em; color: grey;">老铁们关注走一走，不迷路</div> -->

</div>

  
    <div class="post-nav">
      <div class="post-nav-item post-nav-next">
        
          <span>〈 </span>
          <a href="/2019/02/20/深入理解JQuery原理/" rel="next" title="深入理解JQuery原理">
          深入理解JQuery原理
          </a>
        
      </div>
  
      <div class="post-nav-item post-nav-prev">
          
          <a href="/2019/02/28/Oh-my-zsh/" rel="prev" title="Oh-my-zsh">
            Oh-my-zsh
          </a>
          <span>〉</span>
        
      </div>
    </div>
  


    </div>

    
    <div id="vcomments" style="max-width: 800px; margin: 16px auto;"></div>
  </div>
  <footer class="footer text-center">
    <div id="bottom-inner">
        <a class="bottom-item" href="/">首页</a> |
        <a class="bottom-item" href="https://github.com/TJ-XiaJiaHao" target="_blank">GitHub</a> |
        <a class="bottom-item">联系邮箱：1452806@tongji.edu.cn</a>
    </div>
</footer>
  

<script>
  (function(window, document, undefined) {

    var timer = null;

    function returnTop() {
      cancelAnimationFrame(timer);
      timer = requestAnimationFrame(function fn() {
        var oTop = document.body.scrollTop || document.documentElement.scrollTop;
        if (oTop > 0) {
          document.body.scrollTop = document.documentElement.scrollTop = oTop - 50;
          timer = requestAnimationFrame(fn);
        } else {
          cancelAnimationFrame(timer);
        }
      });
    }

    var hearts = [];
    window.requestAnimationFrame = (function() {
      return window.requestAnimationFrame ||
        window.webkitRequestAnimationFrame ||
        window.mozRequestAnimationFrame ||
        window.oRequestAnimationFrame ||
        window.msRequestAnimationFrame ||
        function(callback) {
          setTimeout(callback, 1000 / 60);
        }
    })();
    init();

    function init() {
      css(".heart{z-index:9999;width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: absolute;}.heart:after{top: -5px;}.heart:before{left: -5px;}");
      attachEvent();
      gameloop();
      addMenuEvent();
    }

    function gameloop() {
      for (var i = 0; i < hearts.length; i++) {
        if (hearts[i].alpha <= 0) {
          document.body.removeChild(hearts[i].el);
          hearts.splice(i, 1);
          continue;
        }
        hearts[i].y--;
        hearts[i].scale += 0.004;
        hearts[i].alpha -= 0.013;
        hearts[i].el.style.cssText = "left:" + hearts[i].x + "px;top:" + hearts[i].y + "px;opacity:" + hearts[i].alpha + ";transform:scale(" + hearts[i].scale + "," + hearts[i].scale + ") rotate(45deg);background:" + hearts[i].color;
      }
      requestAnimationFrame(gameloop);
    }

    /**
     * 给logo设置点击事件
     * 
     * - 回到顶部
     * - 出现爱心
     */
    function attachEvent() {
      var old = typeof window.onclick === "function" && window.onclick;
      var logo = document.getElementById("logo");
      if (logo) {
        logo.onclick = function(event) {
          returnTop();
          old && old();
          createHeart(event);
        }
      }
      
    }

    function createHeart(event) {
      var d = document.createElement("div");
      d.className = "heart";
      hearts.push({
        el: d,
        x: event.clientX - 5,
        y: event.clientY - 5,
        scale: 1,
        alpha: 1,
        color: randomColor()
      });
      document.body.appendChild(d);
    }

    function css(css) {
      var style = document.createElement("style");
      style.type = "text/css";
      try {
        style.appendChild(document.createTextNode(css));
      } catch (ex) {
        style.styleSheet.cssText = css;
      }
      document.getElementsByTagName('head')[0].appendChild(style);
    }

    function randomColor() {
      // return "rgb(" + (~~(Math.random() * 255)) + "," + (~~(Math.random() * 255)) + "," + (~~(Math.random() * 255)) + ")";
      return "#F44336";
    }

    function addMenuEvent() {
      var menu = document.getElementById('menu-main-post');
      if (menu) {
        var toc = document.getElementById('toc');
        if (toc) {
          menu.onclick = function() {
            if (toc) {
              if (toc.style.display == 'block') {
                toc.style.display = 'none';
              } else {
                toc.style.display = 'block';
              }
            }
          };
        } else {
          menu.style.display = 'none';
        }
      }
    }

  })(window, document);
</script>

  



</body>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src='//unpkg.com/valine/dist/Valine.min.js'></script>
<script type="text/javascript">
  new Valine({
    el: '#vcomments',
    appId: '8CwYqXS8IoFbvaA9PmgqGjTf-gzGzoHsz',
    appKey: 'z5bVoSPDPhd8hzlXvDey5Hpz',
    verify:false,
    placeholder: '评论留言'
  })
</script>
</html>
